home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 287 < prev    next >
Internet Message Format  |  1996-08-06  |  4KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c,comp.std.c
  4. Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
  5. Date: 02 Feb 1996 18:04:43 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb2110443@qcd.lanl.gov>
  8. References: <30C40F77.53B5@swsbbs.com> <SPENCER.96Jan22113215@zorgon.ERA.COM>
  9.     <TANMOY.96Jan29090518@qcd.lanl.gov> <DM3wEy.FHH@mv.mv.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: ENGR@GSSI.MV.COM's message of Thu, 1 Feb 1996 16:56:57 GMT
  14.  
  15. In article <DM3wEy.FHH@mv.mv.com> ENGR@GSSI.MV.COM (Michael Furman)
  16. writes: 
  17. <snip>
  18.      Not exactly. My question was not about diagnostics, but about usage
  19.    of constructions that are not defined in standard.
  20.    There are two kinds of undefined behavior:
  21.    1. When operation does not have any meaning. Example: assigning a value
  22.      to dereferenced incorrect pointer. In such cases sometimes it is very 
  23.      hard or impossible (at least on some platforms) to check it even at
  24.      execution time and it is really possible that hard disk will be
  25.      reformatted as a result of such operations.
  26.    2. When operation has meaning but can not be portable defined for all
  27.      platforms. Example: all number conversions that depends on internal
  28.      representation or some CPU specific (like rounding). But I have more
  29.      clear example: "asm" keyword. I found it is defined in C++ draft and
  30.      I believe it is defined in C standard. 
  31.      Was it inserted just to give programmers some way to implement undefined
  32.      behavior (with some chance to have disk reformatted)? I do not think so.
  33.  
  34. First, asm is not a C keyword.
  35.  
  36. Next, undefined behaviour doesn't have types. Undefined constructs
  37. have no meaning. i = i++ is just as meaningless as #include <memory.h>
  38. : I have no idea what either of them means. (Note that asm { mov ax,
  39. bx } on the other hand is a syntax error.) An implementation or
  40. another standard is allowed to extend the language by providing
  41. meaning for undefined constructs.
  42.  
  43.    In C++ draft standard there are two words used in such cases: 
  44.    "undefined behavior" and "implementation defined behavior" - and I think
  45.    they are used accordingly for 1. and 2. As I understand now in C standard
  46.    there is no such clear division. But it does not mean that the problem
  47.    does not exist and I believe it is very wrong to claim that in every
  48.    case where behavier is not defined by C standard we may loose all
  49.    data from our hard disk!
  50.  
  51. C does have implementation defined behaviour too. For example, whether
  52. char is signed or unsigned is implementation defined. The
  53. implementation documentation has to specify the choices made for the
  54. implementation defined behaviours.  The standard very clearly
  55. distinguishes between implementation defined and undefined behaviour,
  56. and only very rarely, as in (int)(char*)0, allows an implementation to
  57. define something as undefined (This seems to be the majority view
  58. here: claims have been made that implementation always has the right).
  59.  
  60. So, for undefined behaviour, you may indeed loose all your data on the
  61. hard disk. 
  62.  
  63. Cheers
  64. Tanmoy
  65. --
  66. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  67. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  68. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  69. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  70. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  71. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  72.